package com.zyy.meetObject;

import java.util.Arrays;

public class MyArray {
    public int getMax(int arr[]){
        int Max = arr[0];
        for(int i = 0; i < arr.length; i++ ){
            if(arr[i] > Max){
                Max = arr[i];
            }
        }
        return Max;
    }

    public int  getMin(int arr[]){
        int Min= arr[0];
        for(int i = 0; i < arr.length; i++){
            if(arr[i] < Min){
                Min = arr[i];
            }
        }
        return Min;
    }

    public  int getSum(int arr[]){
        int sum = 0;
        for(int i = 0; i < arr.length; i++){
            sum += arr[i];
        }
        return sum;
    }

    public double getAvg(int arr[]){
        int sum = 0;
        for(int i = 0; i < arr.length; i++){
            sum += arr[i];
        }
        return sum / arr.length;
    }

    public void getArray(int arr[]){
        System.out.println(Arrays.toString(arr));
    }

    public void reversal(int arr[]){
        for(int i = 0; i < arr.length / 2; i++){
            int temp = arr[i];
            arr[i] = arr[arr.length - i - 1];
            arr[arr.length - i - 1] = temp;
        }
        System.out.print("反转后的数组：");
        System.out.println(Arrays.toString(arr));
    }

    public void getSort(int arr[]){
        Arrays.sort(arr);
        System.out.print("排好序的数组：");
        System.out.println(Arrays.toString(arr));
    }

    public  void findnum(int arr[],int num){
        int index = Arrays.binarySearch(arr,num);
        if(index > 0){
            System.out.println("数字在数组下标的" + index + "的位置上");
        }else{
            System.out.println("没有找到");
        }
    }
}
